package com.codedancer.campus.client.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.codedancer.campus.client.service.IFeedbackRecordService;
import com.codedancer.campus.client.service.bo.feedbackRecord.FeedbackRecordAddBo;
import com.codedancer.campus.common.exception.BusinessException;
import com.codedancer.campus.common.utils.UUIDGenerator;
import com.codedancer.campus.mapper.FeedbackRecordMapper;
import com.codedancer.campus.mapper.FeedbackRecordTypeMapper;
import com.codedancer.campus.po.FeedbackRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional(rollbackFor = Exception.class)
public class FeedbackRecordServiceImpl implements IFeedbackRecordService {

    @Autowired
    private FeedbackRecordMapper feedbackRecordMapper;
    @Autowired
    private FeedbackRecordTypeMapper feedbackRecordTypeMapper;

    /**
     * 新增反馈记录
     *
     * @param feedbackRecordAddBo
     */
    @Override
    public void add(FeedbackRecordAddBo feedbackRecordAddBo) {
        if (!feedbackRecordTypeMapper.existsByUuId(
            feedbackRecordAddBo.getFeedbackRecordTypeUuid())) {
            throw new BusinessException("反馈记录类型不存在");
        }
        FeedbackRecord feedbackRecord = BeanUtil.copyProperties(feedbackRecordAddBo,
            FeedbackRecord.class);
        feedbackRecord.setUuid(UUIDGenerator.getUUID());
        feedbackRecord.setFeedbackUserUuid(feedbackRecordAddBo.getCurrentUserUuid());
        feedbackRecordMapper.insert(feedbackRecord);
    }
}
